﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;

using ChiDao.Component.Utils;
using ChiDao.Business.Models;
using ChiDao.Business.Models.FlowProcessNew;
using ChiDao.Site.Models;
using ChiDao.Business.Data.Repositories.FlowProcessNew;


namespace ChiDao.Business.Service.Impl
{
    [Export(typeof(IFlowProcessGraphService))]
    internal class FlowProcessGraphService : IFlowProcessGraphService
    {
        [Import]
        protected IFlowProcessGraphRepository FlowProcessGraphRepository { get; set; }

        public List<FlowProcessGraphView> GetFlowProcessGraph(string processID)
        {
            List<FlowProcessGraphView> flowProcessGraphViewList = new List<FlowProcessGraphView>();
            IQueryable<FlowProcessGraph> flowProcessGraphs = FlowProcessGraphRepository.Entities.Where(c => c.ProcessID == processID);
            foreach (FlowProcessGraph flowProcessGraph in flowProcessGraphs)
            {
                flowProcessGraphViewList.Add(new FlowProcessGraphView()
                {
                    ID = flowProcessGraph.ID,
                    ProcessID = flowProcessGraph.ProcessID,
                    PassProcessNodeCode = flowProcessGraph.PassProcessNodeCode,
                    PassProcessNodeType = flowProcessGraph.PassProcessNodeType
                });
            }
            return flowProcessGraphViewList;
        }

        public void AddFlowProcessGraph(List<FlowProcessGraphView> addList)
        {
            foreach (FlowProcessGraphView flowProcessGraphView in addList)
            {
                FlowProcessGraph flowProcessGraph = new FlowProcessGraph()
                {
                    ID = flowProcessGraphView.ID,
                    ProcessID = flowProcessGraphView.ProcessID,
                    PassProcessNodeCode = flowProcessGraphView.PassProcessNodeCode,
                    PassProcessNodeType = flowProcessGraphView.PassProcessNodeType
                };
                FlowProcessGraphRepository.Insert(flowProcessGraph);
            }
        }
    }
}